﻿using System;
using System.Collections.ObjectModel;

namespace Skyper.Model {
	public sealed class ChatModel : BaseModel {
		#region Fields
		private readonly ContactModel contact;
		private String name;
		private Boolean hasNewMessages;
		private DateTime created;
		private DateTime updated;

		public static readonly ChatModel DesignerPreview = new ChatModel(ContactModel.DesignerPreview) {
			Created = DateTime.Now,
			Updated = DateTime.Now,
			Name = "Test",
		};
		#endregion
		#region Constructor
		public ChatModel(ContactModel contact) {
			this.contact = contact;
			//this.messages= App.Skype.GetMessages(this.contact);
		}
		#endregion
		#region Public
		public override string ToString() {
			if (this.contact == null) {
				return base.ToString();
			}
			return this.contact.ToString();
		}
		#endregion
		#region Property
		/// <summary>
		/// Gets or sets the unique name of this chat.
		/// </summary>
		/// <value>The name.</value>
		public String Name {
			get {
				return this.name;
			}
			set {
				this.name = value;
			}
		}
		/// <summary>
		/// Gets the contact assosiated with this chat.
		/// </summary>
		/// <value>The contact.</value>
		public ContactModel Contact {
			get {
				return this.contact;
			}
		}
		/// <summary>
		/// Gets the messages of this chat.
		/// </summary>
		/// <value>The messages.</value>
		public ObservableCollection<MessageModel> Messages {
			get {
				return App.Skype.GetMessages(this.contact);
			}
		}
		/// <summary>
		/// Gets or sets a value indicating whether this chat has new messages.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this chat has new messages; otherwise, <c>false</c>.
		/// </value>
		public Boolean HasNewMessages {
			get {
				return this.hasNewMessages;
			}
			set {
				if (this.hasNewMessages != value) {
					this.hasNewMessages = value;
					this.OnPropertyChanged("HasNewMessages");
				}
			}
		}

		/// <summary>
		/// Gets or sets the time when this chat was created.
		/// </summary>
		/// <value>The creation time.</value>
		public DateTime Created {
			get {
				return this.created;
			}
			set {
				if (this.created != value) {
					this.created = value;
					this.OnPropertyChanged("Created");
				}
			}
		}
		/// <summary>
		/// Gets or sets the time when this chat was last updated.
		/// </summary>
		/// <value>The updated.</value>
		public DateTime Updated {
			get {
				return this.updated;
			}
			set {
				if (this.updated != value) {
					this.updated = value;
					this.OnPropertyChanged("Updated");
				}
			}
		}
		#endregion
	}
}
